package notice

import (
	"fmt"

	"go-papers/common/go-wechat/common"
	"go-papers/models"
	"go-papers/pkg/wechat"
)

var (
	Template_1 = "80M62Rsss3Q1vkU8MGLj_QQ-rRU2SvqHiuyWEiLgf3o" // 新订单通知
	Template_2 = "XmgBXmEMvCZaJuMjm0tlbq6XCMOft6Opk3DpFGDSL30" // 订单取消
	Template_3 = "eakCxIsqMFtROjc4C9Ur6qikg_uOiqD2E-QccFDMQFk" // 订单排课
	Template_4 = "QCkzeywLCDn8QZv-wMt3quhrWZNtw45LNGj9TCFh2CU" //退款完成通知
	Template_7 = "7wNbrJI_-S4FA7Hipp0JWUOCtvAd3nxSqGjMYNlfyr8" //扣款失败通知
)

func OrderNewMember(openId, openName string, orderInfo models.Order, organ models.Organ) {
	cdata := make(map[string]common.CTemplateMessageItem)

	c := common.CTemplateMessageItem{
		Value: "亲爱的" + openName + " , 您有一笔新订单产生",
		Color: "#173177",
	}
	cdata["first"] = c
	//学员姓名：{{keyword1.DATA}}
	//课程名称：{{keyword2.DATA}}
	//订单金额：{{keyword3.DATA}}
	//订单状态：{{keyword4.DATA}}
	//订单时间：{{keyword5.DATA}}
	//{{remark.DATA}}
	c1 := common.CTemplateMessageItem{
		Value: orderInfo.MemberName,
		Color: "#173177",
	}
	cdata["keyword1"] = c1
	//订单编号
	c2 := common.CTemplateMessageItem{
		Value: orderInfo.CourseName,
		Color: "#173177",
	}
	cdata["keyword2"] = c2
	//商品名称：
	c3 := common.CTemplateMessageItem{
		Value: fmt.Sprintf("%.2f", orderInfo.OrderPrice) + "元",
		Color: "#173177",
	}
	cdata["keyword3"] = c3
	//订单状态
	c4 := common.CTemplateMessageItem{
		Value: "已支付/待确认排课",
		Color: "#173177",
	}
	cdata["keyword4"] = c4

	//订单时间
	c5 := common.CTemplateMessageItem{
		Value: orderInfo.PayTime,
		Color: "#173177",
	}
	cdata["keyword5"] = c5

	//remark
	remark := "  订单编号：" + orderInfo.OrderNo + "\n  机构:"
	remark += organ.OrganName + "(" + organ.OrganTel + ")"
	c6 := common.CTemplateMessageItem{
		Value: remark,
		Color: "",
	}
	cdata["remark"] = c6

	req := &common.CSendTemplateMsgRequest{}
	req.TemplateId = Template_1
	req.Touser = openId
	req.Data = cdata
	req.Url = ""
	_, _ = wechat.Server.Template().SendTemplateMsg(req, 100)

}

func OrderNew(openId, openName string, orderInfo models.Order) {
	cdata := make(map[string]common.CTemplateMessageItem)

	c := common.CTemplateMessageItem{
		Value: "您好，" + openName + " , 平台有一笔新订单产生",
		Color: "#173177",
	}
	cdata["first"] = c
	//学员姓名：{{keyword1.DATA}}
	//课程名称：{{keyword2.DATA}}
	//订单金额：{{keyword3.DATA}}
	//订单状态：{{keyword4.DATA}}
	//订单时间：{{keyword5.DATA}}
	//{{remark.DATA}}
	c1 := common.CTemplateMessageItem{
		Value: orderInfo.MemberName,
		Color: "#173177",
	}
	cdata["keyword1"] = c1
	//订单编号
	c2 := common.CTemplateMessageItem{
		Value: orderInfo.CourseName,
		Color: "#173177",
	}
	cdata["keyword2"] = c2
	//商品名称：
	c3 := common.CTemplateMessageItem{
		Value: fmt.Sprintf("%.2f", orderInfo.OrderPrice) + "元",
		Color: "#173177",
	}
	cdata["keyword3"] = c3
	//订单状态
	c4 := common.CTemplateMessageItem{
		Value: "已支付/待确认排课",
		Color: "#173177",
	}
	cdata["keyword4"] = c4

	//订单时间
	c5 := common.CTemplateMessageItem{
		Value: orderInfo.PayTime,
		Color: "#173177",
	}
	cdata["keyword5"] = c5

	//remark
	remark := "  订单编号：" + orderInfo.OrderNo + "\n  机构:"
	remark += orderInfo.OrganName + "(" + orderInfo.BrandName + ")" + "\n  请尽快与用户联系完成排课"
	c6 := common.CTemplateMessageItem{
		Value: remark,
		Color: "",
	}
	cdata["remark"] = c6

	req := &common.CSendTemplateMsgRequest{}
	req.TemplateId = Template_1
	req.Touser = openId
	req.Data = cdata
	req.Url = ""
	_, _ = wechat.Server.Template().SendTemplateMsg(req, 100)

}

func OrderRefundMsg(openId, openName string, orderInfo models.Order) {
	cdata := make(map[string]common.CTemplateMessageItem)

	c := common.CTemplateMessageItem{
		Value: "您好，" + openName + " , 平台有一笔订单申请退款",
		Color: "#173177",
	}
	cdata["first"] = c
	//{{first.DATA}}
	//申请取消课程：{{keyword1.DATA}}
	//状态：{{keyword2.DATA}}
	//{{remark.DATA}}
	c1 := common.CTemplateMessageItem{
		Value: orderInfo.CourseName,
		Color: "#173177",
	}
	cdata["keyword1"] = c1
	//订单编号
	c2 := common.CTemplateMessageItem{
		Value: "待审核",
		Color: "#173177",
	}
	cdata["keyword2"] = c2

	//remark
	remark := "  下单用户：" + orderInfo.MemberName + "  订单编号：" + orderInfo.OrderNo + "\n  机构:"
	remark += orderInfo.OrganName + "(" + orderInfo.BrandName + ")" + "\n 提交原因：" + orderInfo.RefundReason
	c6 := common.CTemplateMessageItem{
		Value: remark,
		Color: "",
	}
	cdata["remark"] = c6

	req := &common.CSendTemplateMsgRequest{}
	req.TemplateId = Template_2
	req.Touser = openId
	req.Data = cdata
	req.Url = ""
	_, _ = wechat.Server.Template().SendTemplateMsg(req, 100)

}

func OrderShareMsg(openId, openName string, orderInfo models.Order, price, msg string) {
	cdata := make(map[string]common.CTemplateMessageItem)

	c := common.CTemplateMessageItem{
		Value: "您好，" + openName + " , 平台有一笔订单分账失败通知",
		Color: "#173177",
	}
	cdata["first"] = c
	//{{first.DATA}}
	//订单编号：{{keyword1.DATA}}
	//机构名称：{{keyword2.DATA}}
	//课程名称：{{keyword3.DATA}}
	//扣款金额：{{keyword4.DATA}}
	//失败原因：{{keyword5.DATA}}
	//{{remark.DATA}}
	c0 := common.CTemplateMessageItem{
		Value: orderInfo.OrderNo,
		Color: "",
	}
	cdata["keyword1"] = c0
	c1 := common.CTemplateMessageItem{
		Value: orderInfo.OrganName,
		Color: "",
	}
	cdata["keyword2"] = c1
	c2 := common.CTemplateMessageItem{
		Value: orderInfo.CourseName,
		Color: "",
	}
	cdata["keyword3"] = c2
	//订单编号
	c3 := common.CTemplateMessageItem{
		Value: price,
		Color: "",
	}
	cdata["keyword4"] = c3

	c4 := common.CTemplateMessageItem{
		Value: msg,
		Color: "",
	}
	cdata["keyword5"] = c4

	//remark
	remark := "下单用户：" + orderInfo.MemberName + ",确认时间：" + orderInfo.SureTime
	c6 := common.CTemplateMessageItem{
		Value: remark,
		Color: "",
	}
	cdata["remark"] = c6

	req := &common.CSendTemplateMsgRequest{}
	req.TemplateId = Template_7
	req.Touser = openId
	req.Data = cdata
	req.Url = ""
	_, _ = wechat.Server.Template().SendTemplateMsg(req, 100)

}

func OrderSure(openId, openName string, orderInfo models.Order) {
	cdata := make(map[string]common.CTemplateMessageItem)

	c := common.CTemplateMessageItem{
		Value: "您好，" + openName + " , 平台有一笔订单已确认排课",
		Color: "#173177",
	}
	cdata["first"] = c
	//{{first.DATA}}
	//已排课程：{{keyword1.DATA}}
	//上课时间：{{keyword2.DATA}}
	//{{remark.DATA}}
	c1 := common.CTemplateMessageItem{
		Value: orderInfo.MemberName,
		Color: "#173177",
	}
	cdata["keyword1"] = c1
	//订单编号
	c2 := common.CTemplateMessageItem{
		Value: orderInfo.CourseName,
		Color: "#173177",
	}
	cdata["keyword2"] = c2
	//商品名称：
	c3 := common.CTemplateMessageItem{
		Value: "机构安排",
		Color: "#173177",
	}
	cdata["keyword3"] = c3

	//remark
	remark := "  下单用户：" + orderInfo.MemberName + "  订单编号：" + orderInfo.OrderNo + "\n  机构:"
	remark += orderInfo.OrganName + "(" + orderInfo.BrandName + ")" + "\n "
	c6 := common.CTemplateMessageItem{
		Value: remark,
		Color: "",
	}
	cdata["remark"] = c6

	req := &common.CSendTemplateMsgRequest{}
	req.TemplateId = Template_3
	req.Touser = openId
	req.Data = cdata
	req.Url = ""
	_, _ = wechat.Server.Template().SendTemplateMsg(req, 100)

}

func RefundAdmin(openId, openName, username string, orderInfo models.Order) {

	cdata := make(map[string]common.CTemplateMessageItem)

	c := common.CTemplateMessageItem{
		Value: "您好，" + openName + " , 平台有一笔订单完成退款",
		Color: "#173177",
	}
	cdata["first"] = c
	//退款编号
	c1 := common.CTemplateMessageItem{
		Value: orderInfo.RefundNo,
		Color: "#173177",
	}
	cdata["keyword1"] = c1
	//订单编号
	c2 := common.CTemplateMessageItem{
		Value: orderInfo.OrderNo,
		Color: "#173177",
	}
	cdata["keyword2"] = c2
	//商品名称：
	c3 := common.CTemplateMessageItem{
		Value: orderInfo.OrderName,
		Color: "#173177",
	}
	cdata["keyword3"] = c3
	//订单支付金额
	c4 := common.CTemplateMessageItem{
		Value: fmt.Sprintf("%.2f", orderInfo.OrderPrice),
		Color: "#173177",
	}
	cdata["keyword4"] = c4

	//订单退款金额
	c5 := common.CTemplateMessageItem{
		Value: fmt.Sprintf("%.2f", orderInfo.RefundPrice),
		Color: "#173177",
	}
	cdata["keyword5"] = c5

	//remark
	remark := "  下单用户：" + orderInfo.MemberName + "\n  支付时间：" + orderInfo.PayTime + "\n  机构:"
	remark += orderInfo.OrganName + "(" + orderInfo.BrandName + ")" + "\n  操作管理员：" + username
	c6 := common.CTemplateMessageItem{
		Value: remark,
		Color: "",
	}
	cdata["remark"] = c6

	req := &common.CSendTemplateMsgRequest{}
	req.TemplateId = Template_4
	req.Touser = openId
	req.Data = cdata
	req.Url = ""
	_, _ = wechat.Server.Template().SendTemplateMsg(req, 100)

}
